PDA

View Full Version : [CLOSED] How to redirect after login



UnifyEducation
Jun 15, 2012, 3:46 PM
Hi,
Can you tell me how to redirect after login. I'm using ASP.NET MVC. This is my code in Controllers


[AllowAnonymous]
public Ext.Net.MVC.AjaxResult ExtLogin()
{
var username = HttpContext.Request["username"];
var password = HttpContext.Request["password"];
var returnUrl = HttpContext.Request["ReturnUrl"];
if (WebSecurity.Login(username, password) == WebSecurity.MembershipLoginStatus.Success)
{
string script = "window.location.replace('" + returnUrl + "')";
return new Ext.Net.MVC.AjaxResult { Script = script };
}
else
{
return new Ext.Net.MVC.AjaxResult { ErrorMessage = "The username or password is incorrect" };
}

}

Daniil
Jun 15, 2012, 5:48 PM
Hi,

The JavaScript replace method doesn't change a origin string.

Please use:

string script = "window.location = 'http://ext.net'";
return new Ext.Net.MVC.AjaxResult(script);

UnifyEducation
Jun 18, 2012, 8:24 AM
Hi,

The JavaScript replace method doesn't change a origin string.

Please use:

string script = "window.location = 'http://ext.net'";
return new Ext.Net.MVC.AjaxResult(script);

I had tried your code. But it doesn't work.


public Ext.Net.MVC.AjaxResult ExtLogin()
{
string script = "window.location ='http://ext.net'";
return new Ext.Net.MVC.AjaxResult(script);

}

This is my button used in LoginForm:


.Buttons(button =>

button.Add(Html.X().Button()
.ID("btnLogin")
.Icon(Icon.Accept)
.Text("Login")
.DirectEvents(de =>
{
de.Click.Url = "/Account/ExtLogin/";
de.Click.FormID = "loginForm";
de.Click.CleanRequest = true;
de.Click.Timeout = 60000;
de.Click.ExtraParams.Add(new Parameter("ReturnUrl",System.Web.HttpContext.Current.Request["ReturnUrl"]));
de.Click.Method = HttpMethod.POST;
de.Click.Failure = "Ext.Msg.show({title: 'Login Error',msg: result.errorMessage,buttons: Ext.Msg.OK,icon: Ext.MessageBox.ERROR});";
de.Click.EventMask.ShowMask = true;
de.Click.EventMask.MinDelay = 500;
})
.OnClientClick("if (!#{username}.validate() || !#{password}.validate()) {Ext.Msg.alert('Error','The Username and Password fields are both required'); return false; }"))

Daniil
Jun 18, 2012, 10:54 AM
But it doesn't work.

Any error, exception? What does happen? Please provide more details.

What is the response text of the DirectEvent?

UnifyEducation
Jun 19, 2012, 9:25 AM
Any error, exception? What does happen? Please provide more details.

What is the response text of the DirectEvent?

Hi,

There are no error, no exception. Nothing happens, my page did not reload or redirect to other page.
I don't know how to find the response text of DirectEvent.

Daniil
Jun 19, 2012, 12:52 PM
I don't know how to find the response text of DirectEvent.

To inspect requests you can use Developer Tools of IE9 or Chrome, Fiddler, FireBug for FireFox.

Here is the "guide" screenshot for FireBug.
http://forums.ext.net/showthread.php?11377&p=46243&viewfull=1#post46243

UnifyEducation
Jun 19, 2012, 4:29 PM
To inspect requests you can use Developer Tools of IE9 or Chrome, Fiddler, FireBug for FireFox.

Here is the "guide" screenshot for FireBug.
http://forums.ext.net/showthread.php?11377&p=46243&viewfull=1#post46243

Hi,

The response is


{ }

4382
I'm using MVC4, here is my code:


public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

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

routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);

routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}

In global.asax


protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();

FilterConfig.RegisterGlobalFilters(GlobalFilters.F ilters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}

In web.config



<httpHandlers>
<add path="*/ext.axd" verb="*" type="Ext.Net.ResourceHandler" validate="false" />
</httpHandlers>
<httpModules>
<add name="DirectRequestModule" type="Ext.Net.DirectRequestModule, Ext.Net" />
</httpModules>

In Home/Index:


@using Ext.Net
@using Ext.Net.MVC
@{
Layout = null;
}
@Html.X().ResourceManager()
@(Html.X().Button()
.ID("btnLogin")
.Icon(Icon.Accept)
.Text("Login")
.DirectEvents(de =>
{
de.Click.Url = "/Account/ExtLogin/";
de.Click.CleanRequest = true;
de.Click.Timeout = 60000;
de.Click.Method = HttpMethod.POST;
de.Click.Failure = "Ext.Msg.show({title: 'Login Error',msg: result.errorMessage,buttons: Ext.Msg.OK,icon: Ext.MessageBox.ERROR});";
de.Click.EventMask.ShowMask = true;
de.Click.EventMask.MinDelay = 500;
}))

In Account Controller


[AllowAnonymous]
public Ext.Net.MVC.AjaxResult ExtLogin()
{
string script = "window.location ='http://ext.net'";
return new Ext.Net.MVC.AjaxResult(script);
}

Daniil
Jun 19, 2012, 8:59 PM
Does the same work with MVC3 on your side?

What Ext.NET sources do you use?

Daniil
Jun 19, 2012, 9:20 PM
Could you check what is the value of

X.IsAjaxRequest
within the ExtLogin controller action?

UnifyEducation
Jun 20, 2012, 8:07 AM
Could you check what is the value of

X.IsAjaxRequest
within the ExtLogin controller action?

X.IsAjaxRequest = true;
4384
I use Ext.NET sources from svn.

Daniil
Jun 20, 2012, 12:16 PM
I have reproduced it with MVC4. We will investigate.

Vladimir
Jun 20, 2012, 1:21 PM
Please add the following element to root web.config


<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers"
publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc"
publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="4.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages"
publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>


Mode details in the following article (see "Upgrading an ASP.NET MVC 3 Project to ASP.NET MVC 4" item #7)
http://www.asp.net/whitepapers/mvc4-release-notes