How can i insert login view to every page in my asp.net mvc 2.0 project?
I have “stolen” this controllers, and view’s from Non empty project of MS visual studio 2010. How can i insert login form on every view?
I need to use such thing as in php: include. What is in asp.net mvc? ascx???
Here is main.master:
<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
<title>
<asp:ContentPlaceHolder ID="TitleContent" runat="server" />
</title>
<asp:ContentPlaceHolder ID="HeadContent" runat="server" />
<link href="/Content/Site.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="header">
<img src="/Content/image/img_06.jpg" width="320" height="192" /></div>
<div class="naviheader">
<div class="navl">
</div>
<a href="/Home" class="navitext">На главную</a> <a href="/Shedule" class="navitext">
Расписание</a> <a href="/Home/About" class="navitext">О нас</a> <a href="/Admin"
class="navitext">АдминПанель</a>
</div>
<div id="middle">
<div id="container">
<div id="content">
<asp:ContentPlaceHolder ID="MainContent" runat="server">
</asp:ContentPlaceHolder>
</div>
<!-- #content-->
</div>
<!-- #container-->
<div class="sidebar" id="sideLeft">
<asp:ContentPlaceHolder ID="Login" runat="server">
<% Html.RenderPartial("Login"); %>
</asp:ContentPlaceHolder>
</div>
</body>
</html>
where and what i must insert?
here is login view(aspx):
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Main.Master" Inherits="System.Web.Mvc.ViewPage<TrainShedule.Models.LogOnModel>" %>
<asp:Content ID="loginTitle" ContentPlaceHolderID="TitleContent" runat="server">
Log On
</asp:Content>
<asp:Content ID="loginContent" ContentPlaceHolderID="MainContent" runat="server">
<h2>Log On</h2>
<p>
Введите свой логин и пароль:
</p>
<% using (Html.BeginForm()) { %>
<%= Html.ValidationSummary(true, "Login was unsuccessful. Please correct the errors and try again.") %>
<div>
<fieldset>
<legend>Ввод данных:</legend>
<div class="editor-label">
<%= Html.LabelFor(m => m.UserName) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(m => m.UserName) %>
<%= Html.ValidationMessageFor(m => m.UserName) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(m => m.Password) %>
</div>
<div class="editor-field">
<%= Html.PasswordFor(m => m.Password) %>
<%= Html.ValidationMessageFor(m => m.Password) %>
</div>
<div class="editor-label">
<%= Html.CheckBoxFor(m => m.RememberMe) %>
<%= Html.LabelFor(m => m.RememberMe) %>
</div>
<p>
<input type="submit" value="Log On" />
</p>
</fieldset>
</div>
<% } %>
</asp:Content>
First you will need to change your login view page (aspx) to a user contorl (ascx). This shouldn’t be too difficult; copying and pasting with some tweaks should do it.
Once you have your control you can add it to your master page and it will appear on all pages which use the master page. There are 2 ways to add the control to the page.
Drag the UserControl onto the designer surface

Html.RenderUserControl

The following link will help alot. asp.net mvc usercontrols start to finish.