[CLOSED] application not working after using form authentication ( MVC 4 )

  1. #1

    [CLOSED] application not working after using form authentication ( MVC 4 )

    After adding the authentication and authorization in the web config, events has stopped working and I see page is doing a full postback. I tried fiddler but nothing found. If I remove the authorization and authentication it works fine. I have added the followinf line in the global.ascx as well and does not work also DirectEventSubmit event is never fired as page performs a postback.

    Also we have routes.IgnoreRoute("{exclude}/{extnet}/ext.axd");

    protected void Application_AuthenticateRequest(object sender, EventArgs e)
            {
                string url = HttpContext.Current.Request.FilePath;
    
                if (url.EndsWith("ext.axd"))
                {
                    HttpContext.Current.SkipAuthorization = true;
                }
            }
    Web.config
    <?xml version="1.0" encoding="utf-8"?>
    <!--
      For more information on how to configure your ASP.NET application, please visit
      http://go.microsoft.com/fwlink/?LinkId=169433
      -->
    <configuration>
      <configSections>
        <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true"/>
        <section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true"/>
        <section name="extnet" type="Ext.Net.GlobalConfig" requirePermission="false"/>
      </configSections>
      <loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
        <listeners>
          <add name="Rolling Flat File Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" fileName="B:\DeveplomentExtensions\Log\rolling.log" formatter="Text Formatter" rollInterval="Day" rollSizeKB="512000" maxArchivedFiles="1000" traceOutputOptions="LogicalOperationStack, DateTime, Timestamp, ProcessId, ThreadId, Callstack"/>
        </listeners>
        <formatters>
          <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" template="Timestamp: {timestamp}{newline}&#xA;Message: {message}{newline}&#xA;Category: {category}{newline}&#xA;Priority: {priority}{newline}&#xA;EventId: {eventid}{newline}&#xA;Severity: {severity}{newline}&#xA;Title:{title}{newline}&#xA;Machine: {localMachine}{newline}&#xA;App Domain: {localAppDomain}{newline}&#xA;ProcessId: {localProcessId}{newline}&#xA;Process Name: {localProcessName}{newline}&#xA;Thread Name: {threadName}{newline}&#xA;Win32 ThreadId:{win32ThreadId}{newline}&#xA;Extended Properties: {dictionary({key} - {value}{newline})}" name="Text Formatter"/>
        </formatters>
        <categorySources>
          <add switchValue="All" name="General">
            <listeners>
              <add name="Rolling Flat File Trace Listener"/>
            </listeners>
          </add>
        </categorySources>
        <specialSources>
          <allEvents switchValue="All" name="All Events"/>
          <notProcessed switchValue="All" name="Unprocessed Category"/>
          <errors switchValue="All" name="Logging Errors &amp; Warnings">
            <listeners>
              <add name="Rolling Flat File Trace Listener"/>
            </listeners>
          </errors>
        </specialSources>
      </loggingConfiguration>
      <exceptionHandling>
        <exceptionPolicies>
          <add name="ExceptionPolicy">
            <exceptionTypes>
              <add name="All Exceptions" type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="ThrowNewException">
                <exceptionHandlers>
                  <add name="LoggingHandler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" logCategory="General" eventId="100" severity="Error" title="Enterprise Compensation Exception Handling" formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling" priority="0"/>
                  <add name="ReplaceHandler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ReplaceHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" exceptionMessage="{0}. {1} X-XXX-XXX-XXXX with Error Token ID {handlingInstanceID}." replaceExceptionType="Core.Framework.Exceptions.Handler.ExceptionController, Core.Framework.Exceptions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
                </exceptionHandlers>
              </add>
            </exceptionTypes>
          </add>
          <add name="PassThroughPolicy">
            <exceptionTypes>
              <add name="All Exceptions" type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="NotifyRethrow">
                <exceptionHandlers>
                  <add name="PassThroughReplaceHandler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ReplaceHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" replaceExceptionType="Core.Framework.Exceptions.Handler.PassThroughException, Core.Framework.Exceptions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
                </exceptionHandlers>
              </add>
            </exceptionTypes>
          </add>
          <add name="VerbosePolicy">
            <exceptionTypes>
              <add name="All Exceptions" type="System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="ThrowNewException">
                <exceptionHandlers>
                  <add name="Replace Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ReplaceHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" replaceExceptionType="Core.Framework.Exceptions.Handler.ExceptionController, Core.Framework.Exceptions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
                  <add name="Logging Exception Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" logCategory="General" eventId="100" severity="Verbose" title="Enterprise Library Exception Handling" formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling" priority="0"/>
                </exceptionHandlers>
              </add>
            </exceptionTypes>
          </add>
          <add name="CustomPolicy">
            <exceptionTypes>
              <add name="All Exceptions" type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="NotifyRethrow">
                <exceptionHandlers>
                  <add name="Replace Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ReplaceHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" replaceExceptionType="Core.Framework.Exceptions.Handler.CustomExceptionHandler, Core.Framework.Exceptions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
                </exceptionHandlers>
              </add>
            </exceptionTypes>
          </add>
        </exceptionPolicies>
      </exceptionHandling>
      <connectionStrings>
        <!--<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-Compensation.UI-20121130025949;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-Compensation.UI-20121130025949.mdf" providerName="System.Data.SqlClient" />-->
        <add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\aspnet-Compensation.UI-20121130025949.mdf;Initial Catalog=aspnet-Compensation.UI-20121130025949;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />
        <add name="TenantEntities" connectionString="metadata=res://*/EDMX.Tenants.csdl|res://*/EDMX.Tenants.ssdl|res://*/EDMX.Tenants.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=10.1.10.1;initial catalog=Tenant;user id=sa;password=apsiton2012;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
        <add name="Entities" connectionString="metadata=res://*/EDMX.Compensation.csdl|res://*/EDMX.Compensation.ssdl|res://*/EDMX.Compensation.msl;provider=System.Data.SqlClient" providerName="System.Data.EntityClient"/>
      </connectionStrings>
      <appSettings>
        <add key="webpages:Version" value="2.0.0.0" />
        <add key="webpages:Enabled" value="false" />
        <add key="PreserveLoginUrl" value="true" />
        <add key="ClientValidationEnabled" value="true" />
        <add key="UnobtrusiveJavaScriptEnabled" value="true" />
      </appSettings>
      
      <system.web>
        <compilation debug="true" targetFramework="4.5" >
          <assemblies>
            <add assembly="Ext.Net"/>
          </assemblies>
        </compilation>
        <httpRuntime targetFramework="4.5" />
        <authentication mode="Forms">
          <forms loginUrl="~/Login/Login" defaultUrl="~/Desktop/Desktop" timeout="15" />
        </authentication>
        <authorization>
          <deny users="?"/>
        </authorization>
    
        <pages>
          <namespaces>
            <add namespace="System.Web.Helpers" />
            <add namespace="System.Web.Mvc" />
            <add namespace="System.Web.Mvc.Ajax" />
            <add namespace="System.Web.Mvc.Html" />
            <add namespace="System.Web.Optimization" />
            <add namespace="System.Web.Routing" />
            <add namespace="System.Web.WebPages" />
            <add namespace="Ext.Net"/>
            <add namespace="Ext.Net.MVC"/>
          </namespaces>
        </pages>
        <httpModules>
          <add name="DirectRequestModule" type="Ext.Net.DirectRequestModule, Ext.Net"/>
        </httpModules>
        <httpHandlers>
          <add path="*/ext.axd" verb="*" type="Ext.Net.ResourceHandler" validate="false"/>
        </httpHandlers>
      </system.web>
      <system.webServer>
        <validation validateIntegratedModeConfiguration="false" />
        <handlers>
          <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
          <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
          <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
          <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
          <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
          <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
          
          <add name="DirectRequestHandler" verb="*" path="*/ext.axd" preCondition="integratedMode" type="Ext.Net.ResourceHandler"/>
        </handlers>
        <staticContent>
          <mimeMap fileExtension=".json" mimeType="application/json"/>
          <mimeMap fileExtension=".woff" mimeType="application/x-woff"/>
        </staticContent>
        <modules>
          <add name="DirectRequestModule" preCondition="managedHandler" type="Ext.Net.DirectRequestModule, Ext.Net"/>
        </modules>
        
      </system.webServer>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Ext.Net.Utilities" publicKeyToken="2c34ac34702a3c23" culture="neutral"/>
            <bindingRedirect oldVersion="0.0.0.0-2.0.0" newVersion="2.0.1"/>
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed"/>
            <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.5.9"/>
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
      <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
      </entityFramework>
      
      <location path="Scripts">
        <system.web>
          <authorization>
            <allow users="*"/>
          </authorization>
        </system.web>
      </location>
      <location path="extnet">
        <system.web>
          <authorization>
            <allow users="*"/>
          </authorization>
        </system.web>
      </location>
      <location path="extjs">
        <system.web>
          <authorization>
            <allow users="*"/>
          </authorization>
        </system.web>
      </location>
      <location path="ux">
        <system.web>
          <authorization>
            <allow users="*"/>
          </authorization>
        </system.web>
      </location>
      <location path="Content">
        <system.web>
          <authorization>
            <allow users="*"/>
          </authorization>
        </system.web>
      </location>
      <location path="Images">
        <system.web>
          <authorization>
            <allow users="*"/>
          </authorization>
        </system.web>
      </location>
      <location path="Login/Login">
        <system.web>
          <authorization>
            <allow users="*"/>
          </authorization>
        </system.web>
      </location>
      <location path="Resources">
        <system.web>
          <authorization>
            <allow users="*"/>
          </authorization>
        </system.web>
      </location>
    </configuration>
    LoginController.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using Compensation.UI.Controllers.Base;
    using Core.Framework.Model.DesktopModel.Login;
    using Ext.Net;
    using Ext.Net.MVC;
    
    namespace Compensation.UI.Controllers
    {
       
        public class LoginController : Controller
        {
           public ActionResult Login()
           {
               return View();
           }
           
            
            [HttpPost]
            public ActionResult DirectEventSubmit(LoginModel person)
            {
                X.Msg.Alert("Submit", JSON.Serialize(person)).Show();
                return this.Direct();
            }
             
    
        }
    }
    Login.cshtml

    
    @model Core.Framework.Model.DesktopModel.Login.LoginModel
    @{
        ViewBag.Title = "Login";
    }
      @(Html.X().ResourceManager()
      
      .CleanResourceUrl(false)
      )
            @section Content
            {
                
                @(
                
                 Html.X().Window()
                .Title("Submit")
                .Width(250)
                .Height(220)
                .Layout(LayoutType.Fit)
                .Closable(false)
                .Border(false)
                .Items(
                    Html.X().FormPanel()
                        .ID("FormPanel1")
                        .Frame(true)
                        .DefaultAnchor("100%")
                        .BodyPadding(6)
                        .FieldDefaults(def =>
                        {
                            def.MsgTarget = MessageTarget.Side;
                        })
                        .Items(
                            
                            Html.X().TextFieldFor(m => m.UserName),
                            Html.X().TextFieldFor(m => m.Password),
                            Html.X().TextFieldFor(m => m.CompanyId)
                            
                        )
                )
                .Buttons(
                    Html.X().Button()
                      
                        .Text("Login")
                                .DirectEvents(de => {
                                    de.Click.Url = Url.Action("DirectEventSubmit");
                                    de.Click.EventMask.ShowMask = true;
                                    de.Click.FormID = "FormPanel1";
                                })
                        )
                )
                
                
                 
    
                  
    
                      
                      
                      
            }
    Last edited by Daniil; Dec 07, 2012 at 6:43 AM. Reason: [CLOSED]
  2. #2
    I guess that ASP.NET redirects you to login page because anonymous access to DirectEventSubmit is forbidden
    I don't see where you handle authorization (doing 'FormsAuthentication.RedirectFromLoginPage' or 'FormsAuthentication.SetAuthCookie' or something else)
    You can try to rename DirectEventSubmit to Login (the same name as view action, just with onther arguments)
    Or you can try to allow anonymous access to whole login controller (or DirectEventSubmit action only)
  3. #3
    Quote Originally Posted by Vladimir View Post
    I guess that ASP.NET redirects you to login page because anonymous access to DirectEventSubmit is forbidden
    I don't see where you handle authorization (doing 'FormsAuthentication.RedirectFromLoginPage' or 'FormsAuthentication.SetAuthCookie' or something else)
    You can try to rename DirectEventSubmit to Login (the same name as view action, just with onther arguments)
    Or you can try to allow anonymous access to whole login controller (or DirectEventSubmit action only)
    Thank you Vladimir, the issue is how can i set the form authentication auth cookie when authentication has not happened. Can you please provide a small sample. Works if I am not using ext.net thought.

    Thank you
  4. #4
    Please see my previous answer
    You can try to rename DirectEventSubmit to Login (the same name as view action, just with onther arguments)
    Or you can try to allow anonymous access to whole login controller (or DirectEventSubmit action only)

Similar Threads

  1. Replies: 2
    Last Post: Oct 18, 2012, 8:05 AM
  2. [CLOSED] Forms authentication RedirectFromLoginPage not working
    By CarWise in forum 2.x Legacy Premium Help
    Replies: 5
    Last Post: Jun 05, 2012, 1:25 PM
  3. Application stops working after some time
    By mercede75 in forum 1.x Help
    Replies: 0
    Last Post: May 18, 2012, 6:47 AM
  4. Replies: 2
    Last Post: Dec 07, 2011, 4:37 AM
  5. Replies: 4
    Last Post: Apr 28, 2011, 2:28 AM

Posting Permissions