2013-08-10 11 views
0

Я использую mvc3 с бритвой У меня есть кнопка для SignOut пользователя, я использую следующий код общих/_layout.cshtmlфункция SignOut на событии нажатия кнопки в MVC3 в рамках сущности

 //button 
    <div class="button"><a href="#" id="Logout" title="Logout"> 


      <div class="Logout"></div>Logout</a></div> 
    <script> 
      $("#Logout").bind("click", function() { 
window.location.href = '@Url.Action("LogOn", "Account")'; 
}); 
    </script> 

accountcontroller.cs 

public ActionResult Logout() 
     { 
      FormsAuthentication.SignOut(); 
      return RedirectToAction("LogOn"); 
     } 

Этих направляет меня на страницу с ошибкой

http://localhost:XXXX/%3C%=%20Url.Action(%22Logout%22,%20%22Account%22)%20%%3E 

Server Error in '/' Application. 

HTTP Error 400 - Bad Request. 

Version Information: ASP.NET Development Server 11.0.0.0 

может кто-нибудь сказать мне, где я буду не так? Пожалуйста, помогите нам выбрать событие щелчка, чтобы внести изменения.

Обновлено:

http://localhost:8436/&#47;Account&#47;Logout 


enter code here 
Server Error in '/' Application. 

A potentially dangerous Request.Path value was detected from the client (&). 

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Web.HttpException: A potentially dangerous Request.Path value was detected from the client (&). 

Source Error: 

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

    Stack Trace: 


    [HttpException (0x80004005): A potentially dangerous Request.Path value was detected from the client (&).] 
     System.Web.HttpRequest.ValidateInputIfRequiredByConfig() +9673044 
     System.Web.ValidateRequestExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +35 
     System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155 
+0

были у ошибочно написано как Url.Action («LogOn», «Счет») он должен быть –

+0

благодаря Bходу в систему Нитина :) я исправил .. Но пожалуйста проверить мое обновление – gs11111

+0

попробовать использовать ValidateInput (ложь) к действию –

ответ

1

бритву синтаксис использования и @ символ вместо <%, так что используйте это, и все должно работать нормально

$("#Logout").bind("click", function() { 
    window.location.href = '@Url.Action("LogOn", "Account")'; // assuming this is the correct action you want to use for the logout button 
}); 

Вы также можете переключиться с JQuery $("#Logout").bind в $("#Logout").click

+0

Я сделал изменения, но я получаю еще одну ошибку securiy. , пожалуйста, проверьте мое обновление – gs11111

1

Почему бы вам не попробовать ajax jquery call

<a href="#" id="Logout" onclick=="return LogOut();" title="Logout"> 

function LogOut() { 
$.ajax({ 
          cache:true, 
          type: "POST", 
          url: "@(Url.Action("LogOut", "Account"))", 
          success: function (data) { 
               window.location.reload(); 
              }, 
          error:function (xhr, ajaxOptions, thrownError){ 

               }, 
          complete: function() { } 

          }); // end ajax code 
        } 

Это может показаться длинным, но должно работать!

 Смежные вопросы

  • Нет связанных вопросов^_^