asp.net mvc 3-在应用程序文件夹/子域中运行MVC3可以让我获得级联URL



我有一个主网站http://sol3.net/.我在\caergalen的主网站下添加了一个应用程序目录,并将其映射到位于http://caergalen.sol3.net/.到目前为止,一切似乎都很好——直到我尝试登录。

注意:当我在dev中作为一个独立的应用程序运行时,登录可以正常工作。

当我点击登录按钮时,我会进入http://caergalen.sol3.net/Account/LogOn。到目前为止还不错。

当我选择我的openid(并进行登录)时,我会在处结束http://caergalen.sol3.net/CaerGalen/帐户/注册。(我的帐户尚未与该网站关联)。但请注意,我的应用程序目录的名称现在是URL的一部分!


附录:

我的控制器:

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Security.Principal;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.Security;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OpenId;
using DotNetOpenAuth.OpenId.Extensions.SimpleRegistration;
using DotNetOpenAuth.OpenId.RelyingParty;
using DotNetOpenAuth.OpenId.Extensions.AttributeExchange;
using CaerGalenMvc.Models;
namespace CaerGalenMvc.Controllers
{
    public class AccountController : Controller
    {
        private static OpenIdRelyingParty openid = new OpenIdRelyingParty();
        public IFormsAuthenticationService FormsService { get; set; }
        public IMembershipService MembershipService { get; set; }
        protected override void Initialize(RequestContext requestContext)
        {
            if (FormsService == null) { FormsService = new FormsAuthenticationService(); }
            if (MembershipService == null) { MembershipService = new AccountMembershipService(); }
            base.Initialize(requestContext);
        }
        // **************************************
        // URL: /Account/LogOn
        // **************************************
        public ActionResult LogOn()
        {
            return View();
        }
        [HttpPost]
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (MembershipService.ValidateUser(model.UserName, model.Password))
                {
                    FormsService.SignIn(model.UserName, model.RememberMe);
                    if (Url.IsLocalUrl(returnUrl))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        return RedirectToAction("Index", "Home");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }
            // If we got this far, something failed, redisplay form
            return View(model);
        }
        // **************************************
        // URL: /Account/LogOff
        // **************************************
        public ActionResult LogOff()
        {
            FormsService.SignOut();
            return RedirectToAction("Index", "Home");
        }
        // **************************************
        // URL: /Account/Register
        // **************************************
        public ActionResult Register()  //string OpenID)
        {
            ViewBag.PasswordLength = MembershipService.MinPasswordLength;
            ViewBag.OpenID = Session["OpenID"].ToString();
            return View();
        }
        [HttpPost]
        public ActionResult Register(cgUser model)
        {
            model.OpenID = Session["OpenID"].ToString();
            if (!ModelState.IsValid)
            {
                var errors = ModelState.Where(x => x.Value.Errors.Count > 0)
                                       .Select(x => new { x.Key, x.Value.Errors })
                                       .ToArray();
                int count = errors.Count();
            }
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                string PWD = string.Format("{0} {1}", model.MundaneFirstName, model.MundaneLastName);
                MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, PWD, model.Email, model.OpenID);
                if (createStatus == MembershipCreateStatus.Success)
                {
                    FormsService.SignIn(model.UserName, false);
                    Session["OpenID"] = null;
                    return RedirectToAction("Index", "Home", null);
                }
                else
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                }
            }
            // If we got this far, something failed, redisplay form
            ViewBag.PasswordLength = MembershipService.MinPasswordLength;
            return View(model);
        }
        // **************************************
        // URL: /Account/ChangePassword
        // **************************************
        [Authorize]
        public ActionResult ChangePassword()
        {
            ViewBag.PasswordLength = MembershipService.MinPasswordLength;
            return View();
        }
        [Authorize]
        [HttpPost]
        public ActionResult ChangePassword(ChangePasswordModel model)
        {
            if (ModelState.IsValid)
            {
                if (MembershipService.ChangePassword(User.Identity.Name, model.OldPassword, model.NewPassword))
                {
                    return RedirectToAction("ChangePasswordSuccess");
                }
                else
                {
                    ModelState.AddModelError("", "The current password is incorrect or the new password is invalid.");
                }
            }
            // If we got this far, something failed, redisplay form
            ViewBag.PasswordLength = MembershipService.MinPasswordLength;
            return View(model);
        }
        // **************************************
        // URL: /Account/ChangePasswordSuccess
        // **************************************
        public ActionResult ChangePasswordSuccess()
        {
            return View();
        }
        [ValidateInput(false)]
        public ActionResult Authenticate(string returnUrl)
        {
            var response = openid.GetResponse();
            if (response == null)
            {
                //Let us submit the request to OpenID provider
                Identifier id;
                if (Identifier.TryParse(Request.Form["openid_identifier"], out id))
                {
                    try
                    {
                        var request = openid.CreateRequest(Request.Form["openid_identifier"]);
                        return request.RedirectingResponse.AsActionResult();
                    }
                    catch (ProtocolException ex)
                    {
                        ViewBag.Message = ex.Message;
                        return View("LogOn");
                    }
                }
                ViewBag.Message = "Invalid identifier";
                return View("LogOn");
            }
            //Let us check the response
            switch (response.Status)
            {
                case AuthenticationStatus.Authenticated:
                    LogOnModel lm = new LogOnModel();
                    lm.OpenID = response.ClaimedIdentifier;
                    // check if user exist
                    MembershipUser user = MembershipService.GetUser(lm.OpenID);
                    if (user != null)
                    {
                        lm.UserName = user.UserName;
                        FormsService.SignIn(user.UserName, false);
                        return RedirectToAction("Index", "Home");
                    }
                    // Need to register them now...
                    ViewBag.LogOn = lm;
                    ViewBag.PasswordLength = MembershipService.MinPasswordLength;
                    RegisterModel rm = new RegisterModel();
                    Session["OpenID"] = lm.OpenID;
                    return RedirectToAction("Register");
                case AuthenticationStatus.Canceled:
                    ViewBag.Message = "Canceled at provider";
                    return View("LogOn");
                case AuthenticationStatus.Failed:
                    ViewBag.Message = response.Exception.Message;
                    return View("LogOn");
            }
            return new EmptyResult();
        }
    }
}

我的登录视图:

@model CaerGalenMvc.Models.LogOnModel
@{ ViewBag.Title = "Log On"; }
<form action="Authenticate?ReturnUrl=@HttpUtility.UrlEncode(Request.QueryString["ReturnUrl"])" method="post" id="openid_form" class="openid">
<input type="hidden" name="action" value="verify" />
<fieldset class="ShowBorder">
    <legend>Login using OpenID</legend>
    <div>
        <ul class="providers">
            <li class="openid" title="OpenID">
                <img src="/content/images/openidW.png" alt="icon" />
                <span><strong>http://{your-openid-url}</strong></span></li>
            <li class="direct" title="Google">
                <img src="/content/images/googleW.png" alt="icon" /><span>https://www.google.com/accounts/o8/id</span></li>
            <li class="direct" title="Yahoo">
                <img src="/content/images/yahooW.png" alt="icon" /><span>http://yahoo.com/</span></li>
            <li class="username" title="AOL screen name">
                <img src="/content/images/aolW.png" alt="icon" /><span>http://openid.aol.com/<strong>username</strong></span></li>
            <li class="username" title="MyOpenID user name">
                <img src="/content/images/myopenid.png" alt="icon" /><span>http://<strong>username</strong>.myopenid.com/</span></li>
            <li class="username" title="Flickr user name">
                <img src="/content/images/flickr.png" alt="icon" /><span>http://flickr.com/<strong>username</strong>/</span></li>
            <li class="username" title="Technorati user name">
                <img src="/content/images/technorati.png" alt="icon" /><span>http://technorati.com/people/technorati/<strong>username</strong>/</span></li>
            <li class="username" title="Wordpress blog name">
                <img src="/content/images/wordpress.png" alt="icon" /><span>http://<strong>username</strong>.wordpress.com</span></li>
            <li class="username" title="Blogger blog name">
                <img src="/content/images/blogger.png" alt="icon" /><span>http://<strong>username</strong>.blogspot.com/</span></li>
            <li class="username" title="LiveJournal blog name">
                <img src="/content/images/livejournal.png" alt="icon" /><span>http://<strong>username</strong>.livejournal.com</span></li>
            <li class="username" title="ClaimID user name">
                <img src="/content/images/claimid.png" alt="icon" /><span>http://claimid.com/<strong>username</strong></span></li>
            <li class="username" title="Vidoop user name">
                <img src="/content/images/vidoop.png" alt="icon" /><span>http://<strong>username</strong>.myvidoop.com/</span></li>
            <li class="username" title="Verisign user name">
                <img src="/content/images/verisign.png" alt="icon" /><span>http://<strong>username</strong>.pip.verisignlabs.com/</span></li>
        </ul>
    </div>
    <fieldset class="NoBorder">
        <label for="openid_username">
            Enter your <span>Provider user name</span></label>
        <div>
            <span></span>
            <input type="text" name="openid_username" /><span></span>
            <input type="submit" value="Login" /></div>
    </fieldset>
    <fieldset class="NoBorder">
        <label for="openid_identifier">
            Enter your <a class="openid_logo" href="http://openid.net">OpenID</a></label>
        <div>
            <input type="text" name="openid_identifier" />
            <input type="submit" value="Login" /></div>
    </fieldset>
    <noscript>
        <p>
            OpenID is service that allows you to log-on to many different websites using a single indentity. Find 
            out <a href="http://openid.net/what/">more about OpenID</a>and <a href="http://openid.net/get/">how to 
            get an OpenID enabled account</a>.</p>
    </noscript>
    <div>
            @if (Model != null)
            {
                // User does not exist...
                if (String.IsNullOrEmpty(Model.UserName))
                {
                <p>As this is your first time trying to login to this site you will need to complete our registration form.</p>
                <p class="button">
                    @Html.ActionLink("New User ,Register", "Register", new { OpenID = Model.OpenID })
                </p>
                }
                else
                {
                //user exists...
                <p class="buttonGreen">
                    <a href="@Url.Action("Index", "Home")">Welcome , @Model.UserName, Continue..." </a>
                </p>
                }
            }
        </div>
</fieldset>
</form>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.openid.js")" type="text/javascript"></script>
<script type="text/javascript">    $(function () { $("form.openid:eq(0)").openid(); });</script>

我的注册视图:

@model CaerGalenMvc.Models.cgUser
@{ ViewBag.Title = "Register"; }
<h2>Create a New Account</h2>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Html.BeginForm()) {
    <div>
        <fieldset>
            <legend></legend>
            @Html.ValidationSummary(true, "Account creation was unsuccessful.  Please correct the errors and try again.")
            <p>
                Use the form below to create a new account.  Items with an <span style="color:red">**</span> are required.</p>
            @*<p>
                Passwords are required to be a minimum of @ViewBag.PasswordLength characters in length.</p>*@
            <p>
                All information collected here is for the express reason of making your visit to this site personalized.  Mundane 
                information collected will not be sold or released without your written (or electronic signature) permission.</p>
            <p>
                This site will have several contact pages where someone can come to the page and select you (by Society name only) 
                as a recipient and this site will send you an email.  The person originating the contact will not be getting an 
                email.  After you receive the email it is up to you to respond or not as you feel fit and/or comfortable doing
                so.</p>
            <hr />
            <br />
            <table>
                <tr>
                    <td colspan="2"><h3>Account Information</h3></td>
                </tr>
                @if (ViewBag.OpenID != null || ViewData["OpenID"] != null)
                {
                <tr>
                    <td class="editor-label">@Html.Label("OpenID"):</td>
                    <td class="editor-field">
                        You have been successfully authenticated by your login provider!
                    </td>
                </tr>
                }
                <tr>
                    <td class="editor-label">@Html.LabelFor(m => m.Email):</td>
                    <td class="editor-field">@Html.TextBoxFor(m => m.Email) <span style="color:red">**</span> @Html.ValidationMessageFor(m => m.Email)</td>
                </tr>
                <tr>
                    <td class="editor-label">@Html.LabelFor(m => m.UserName):</td>
                    <td class="editor-field">@Html.TextBoxFor(m => m.UserName) <span style="color:red">**</span> @Html.ValidationMessageFor(m => m.UserName)</td>
                </tr>
                <tr>
                    <td colspan="2"><br /><h3>Society Information</h3></td>
                </tr>
                <tr>
                    <td class="editor-label">@Html.LabelFor(m => m.SocietyTitle):</td>
                    <td class="editor-field">@Html.TextBoxFor(m => m.SocietyTitle)@Html.ValidationMessageFor(m => m.SocietyTitle)</td>
                </tr>
                <tr>
                    <td class="editor-label">@Html.LabelFor(m => m.SocietyFirstName):</td>
                    <td class="editor-field">@Html.TextBoxFor(m => m.SocietyFirstName)@Html.ValidationMessageFor(m => m.SocietyFirstName)</td>
                </tr>
                <tr>
                    <td class="editor-label">@Html.LabelFor(m => m.SocietyMiddleName):</td>
                    <td class="editor-field">@Html.TextBoxFor(m => m.SocietyMiddleName)@Html.ValidationMessageFor(m => m.SocietyMiddleName)</td>
                </tr>
                <tr>
                    <td class="editor-label">@Html.LabelFor(m => m.SocietyLastName):</td>
                    <td class="editor-field">@Html.TextBoxFor(m => m.SocietyLastName)@Html.ValidationMessageFor(m => m.SocietyLastName)</td>
                </tr>
                <tr>
                    <td colspan="2"><br /><h3>Mundane Information</h3></td>
                </tr>
                <tr>
                    <td class="editor-label">@Html.LabelFor(m => m.MundaneFirstName)</td>
                    <td class="editor-field">@Html.TextBoxFor(m => m.MundaneFirstName) <span style="color:red">**</span> @Html.ValidationMessageFor(m => m.MundaneFirstName)</td>
                </tr>
                <tr>
                    <td class="editor-label">@Html.LabelFor(m => m.MundaneMiddleName)</td>
                    <td class="editor-field">@Html.TextBoxFor(m => m.MundaneMiddleName)@Html.ValidationMessageFor(m => m.MundaneMiddleName)</td>
                </tr>
                <tr>
                    <td class="editor-label">@Html.LabelFor(m => m.MundaneLastName)</td>
                    <td class="editor-field">@Html.TextBoxFor(m => m.MundaneLastName) <span style="color:red">**</span> @Html.ValidationMessageFor(m => m.MundaneLastName)</td>
                </tr>
                <tr>
                    <td class="editor-label">@Html.LabelFor(m => m.PhoneNumberPrimary)</td>
                    <td class="editor-field">@Html.TextBoxFor(m => m.PhoneNumberPrimary)@Html.ValidationMessageFor(m => m.PhoneNumberPrimary)</td>
                </tr>
                <tr>
                    <td class="editor-label">@Html.LabelFor(m => m.PhoneNumberSecondary)</td>
                    <td class="editor-field">@Html.TextBoxFor(m => m.PhoneNumberSecondary)@Html.ValidationMessageFor(m => m.PhoneNumberSecondary)</td>
                </tr>
                <tr>
                    <td class="editor-label">@Html.LabelFor(m => m.PhoneContactInfo)</td>
                    <td class="editor-field">@Html.TextBoxFor(m => m.PhoneContactInfo)@Html.ValidationMessageFor(m => m.PhoneContactInfo)</td>
                </tr>
                <tr>
                    <td class="editor-label">&nbsp;</td>
                    <td class="editor-field"><input type="submit" value=" Register " /></td>
                </tr>
            </table>
        </fieldset>
    </div>
}

然后,我填写了必填字段,然后单击"注册",结果出现了一个错误有些东西不太正常,我不够聪明,不能说"啊哈!那是错误的事情。"

有谁有什么见解吗?

这看起来像是一个关于如何在应用程序中设置重定向链接的问题。这很可能是一个视图问题,所以我会先查看视图中的值。如果需要,将重定向链接的值作为临时的"将其抛出到浏览器"选项。

如果链接是在控制器中设置的(查看控制器中更改的模型),等等,你可以设置断点,看看发生了什么

一旦你确定了问题所在,你就有足够的信息来解决这个问题。

最新更新