ASP.Net无法成功登录/注册(在本地运行,但不能在Azure上运行) [英] ASP.Net Can't Login/Register successfully ( works locally but not on Azure )

查看:38
本文介绍了ASP.Net无法成功登录/注册(在本地运行,但不能在Azure上运行)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Edit2:我发现它可以正确登录并提供用户的cookie(.AspNet.ApplicationCookie),但是当它存在时(在WebApp的部署版本上运行,而不是在本地运行)负载,所以永恒的负载只是重定向到主页,我不知道它可能是什么.

起初,我坚信数据库连接有问题或什么问题……但是我只是通过在本地登录管理面板才意识到,我尝试使用已部署的Web App注册的帐户已成功在数据库中注册,即使完成注册后,您仍会停留在永恒的加载屏幕中.

At first i tought it was the Database connection that was wrong or something... but i just realised by login in the admin panel locally that the accounts i was trying to register using the deployed Web App were registering in the DB successfully, even though after doing the registration you are stuck in an eternal loading screen..

我不知道这可能是什么问题,因为它在本地100%起作用,但是以某种方式似乎无法在Azure中部署它时登录/登录.

I don't know what could be wrong since it is 100% functional locally , but somehow it seems like you can't sign in/login when it is deployed in Azure.

今天早晨,我以某种方式尝试登录,但它给了我运行时错误:

Edit : Somehow this morning i've tried logging in and it gave me a Runtime Error :

"/"应用程序中的服务器错误.运行时错误说明:处理您的请求时发生异常.此外,执行自定义时发生另一个异常第一个异常的错误页面.请求已终止

Server Error in '/' Application. Runtime Error Description: An exception occurred while processing your request. Additionally, another exception occurred while executing the custom error page for the first exception. The request has been terminated

现在有人问我更多信息:

Now i've been asked the more info :

在本地测试时,请确保该应用程序不是在项目的App_Data文件夹中创建任何.mdf文件文件系统.如果是这样,这肯定表明了它为什么起作用本地,但部署到天蓝色时则不行.从技术上讲,您可以单独的连接字符串,从而为您的单独的数据库应用程序和您的应用程序服务.

When you test locally, make certain that the application is not creating any .mdf files in within your project's App_Data folder on the filesystem. If it is, this is a sure indication as to why it works locally but not when deployed to azure. Technically, you can have separate connection strings and thus separate databases for your application and your application services.

当我在本地测试时,App_Data文件夹中没有文件,因为它在部署时与在本地运行时使用相同的数据库->可以在本地和部署中注册新帐户

When i test locally, no file is made in the App_Data folder as it uses the same database while deploying as when running it locally -> can register new accounts locally and on the deploy

现在开始:

请使用您的web.config文件更新您的问题.一定要

Please update your question with your web.config file. Be sure to

在"

.异常消息表明连接您用于应用程序服务的字符串名称(表示成员身份,角色管理等)引用存在的数据库在您的App_Data目录中.请务必省略任何用户名和发布web.config时输入的密码.

. The exception message indicates that the connection string name you are using for application services (meaning membership, role management, etc) is referencing a database that lives in your App_Data directory. Be sure to omit any usernames and passwords from your when you post the web.config.

在我的Web.config中,我没有任何roleManager部分,也没有成员身份(我不使用成员身份,但我确实使用roleManager?)

In my Web.config i do not have any roleManager section nor membership(i don't use membership but i do use roleManager?)

请按此处要求提供一些重要的注册代码:

as per requested here is some important code with the registration :

这是当有人注册(AccountController)时发生的事情

This is what happens when someone register ( AccountController )

[HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
                user.Subscribed = false;
                user.StartSubscription = new DateTime?();
                user.EndSubscription = null;
                user.paypalProfileID = null;

                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return RedirectToAction("Index", "Home");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }

这是ApplicationUser身份:

and this is the ApplicationUser identity :

public class ApplicationUser : IdentityUser
    {
        public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
        {
            // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
            var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
            // Add custom user claims here
            return userIdentity;
        }
        public string paypalProfileID { get; set; }
        public bool? Subscribed { get; set; }
        public DateTime? StartSubscription { get; set; }
        public DateTime? EndSubscription { get; set; }
    }

    public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    {
        public ApplicationDbContext()
            : base("DefaultConnection", throwIfV1Schema: false)
        {
        }

        public static ApplicationDbContext Create()
        {
            return new ApplicationDbContext();
        }
    }

推荐答案

&#$& $#@& @#$ U @#$ $ @# $#@ #@ $ #@ $ *(!$(@()@#($!@(@ $(@ $

&#$&$#@&@#$U@#$$@#$#@#@$#@$*(!$(@()@#($!@(@$(@$

一直是资产净值:

 @if (User.IsInRole("admin"))
                    {
                        <li>@Html.ActionLink("Admin", "AdminPage", "Admin")</li>
                    }

没有

<system.webServer>
    <modules>
        <remove name="RoleManager" />
    </modules>
</system.webServer>

在Web.Config中

in the Web.Config

...

这篇关于ASP.Net无法成功登录/注册(在本地运行,但不能在Azure上运行)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆