Original http://www.cnblogs.com/aehyok/archive/2013/04/22/3035302.html
Determine the isauthenticated method of the request before and after logon. Because the server segmentCodeExecute different scripts, so we need to extract the Loder public code into a script block independently, and different scripts in different codes, the final code is as follows:
<SCRIPT type = " Text/JavaScript " > Ext. loader. setconfig ({enabled: True , Paths :{ ' Ext. UX ' : ' Scripts/extjs/UX ' , ' Extmvcone ' : ' Scripts/APP ' }); Ext. NS ( ' Extmvcone ' ); // Ext. Require ('ext. UX. login '); // Ext. onready (function (){ // If (ext. blank_image_url.substr (0, 4 )! = "Data "){ // Ext. blank_image_url = "content/images/s.gif "; // } // Ext. UX. login. Show (); // }) </SCRIPT>
comment out the previous logon logs. because you want to call the Program to generate an interface, you need to let ext JS know the application directory, therefore, add the following code to the paths of Loader: 'extmvcone' :< span style = "color: maroon; "> 'scripts/app'
After Authentication, you need to write user information such as an object to control the permissions of the application. Therefore, add the following code:
VaR Roles = Roles. getrolesforuser (user. Identity. Name ); VaR Rolesstring = "" ; Foreach ( VaR C In Roles) {rolesstring + = String . Format ( " '{0 }', " , C);} rolesstring = Rolesstring. substring ( 0 , Rolesstring. Length- 1 ); <SCRIPT type = " Text/JavaScript " > Extmvcone. userinfo = {Roles: [@ html. Raw (rolesstring)]}; </SCRIPT>
here, the user role is simply written into the userinfo object. If you need other user information, you can construct the object based on the actual situation, as long as it is easy to access.
There is a problem here, that is, all objects simplecms may be null here, so you need to call the NS method of ext to name it. This can be added to the loader and the code is as follows:
Ext. NS ('Extmvcone');
Then run and log on to the system through Firefox firenbug. I logged on to the admin as the system administrator.
Finally, all the code in the index View
@ {Layout = Null ;} <! Doctype HTML> " Content-Type " Content = " Text/html; charset = UTF-8 " /> <LINK rel = " Stylesheet " Type = " Text/CSS " Href =" @ URL. Content ( " Scripts/extjs/resources/CSS/ext-all.css " ) " /> <SCRIPT type = " Text/JavaScript " Src = " @ URL. Content ( " Scripts/extjs/Bootstrap. js " ) " > </SCRIPT> <SCRIPT type = " Text/JavaScript " Src = " @ URL. Content ( " Scripts/extjs/Ext-lang-zh_CN.js " ) " > </SCRIPT> " Text/JavaScript " > Ext. loader. setconfig ({enabled: True , Paths :{ ' Ext. UX ' : ' Scripts/extjs/UX ' , ' Extmvcone ' : ' Scripts/APP ' }); Ext. NS ( ' Extmvcone ' ); // Ext. Require ('ext. UX. login '); // Ext. onready (function (){ // If (ext. blank_image_url.substr (0, 4 )! = "Data "){ // Ext. blank_image_url = "content/images/s.gif "; // } // Ext. UX. login. Show (); // }) </SCRIPT> @{ If (Request. isauthenticated ){ VaR Roles = Roles. getrolesforuser (user. Identity. Name ); VaR Rolesstring = "" ; Foreach ( VaR C In Roles) {rolesstring + = String . Format ( " '{0 }', " , C);} rolesstring = Rolesstring. substring ( 0 , Rolesstring. Length- 1 ); <SCRIPT type = " Text/JavaScript " > Extmvcone. userinfo = {Roles: [@ html. Raw (rolesstring)]}; </SCRIPT> } Else { <SCRIPT> Ext. Require ( ' Ext. UX. Login ' ); Ext. onready (function (){ If (Ext. blank_image_url.substr ( 0 , 4 )! = " Data " ) {Ext. blank_image_url = " Content/images/s.gif " ;}Ext. UX. login. Show ();}) </SCRIPT>}} </Body>