如何处理这些错误 [英] How to handle these Errors
本文介绍了如何处理这些错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
1. VS 2012 for web对这个tutorail有效
2.作为我我正在使用VS 2012,因此默认情况下它不会创建模型文件夹。
3.并且没有默认类IndentityModels.cs。我正在手动创建该类但它给出了很多错误。即
使用 Microsoft.AspNet.Identity;
使用 Microsoft.AspNet.Identity.EntityFramework;
使用 Microsoft.Owin.Security;
使用 System.Web;
使用系统;
使用 WingtipToys.Models;
命名空间 WingtipToys.Models
{
// 您可以通过向User类添加更多属性来为用户添加用户数据,请访问http://go.microsoft.com/fwlink/?LinkID=317594以了解更多信息。
public class ApplicationUser:IdentityUser
{
}
public class ApplicationDbContext:IdentityDbContext< applicationuser>
{
public ApplicationDbContext()
: base ( DefaultConnection)
{
}
}
#region助手
public 类 UserManager:UserManager< applicationuser>
{
public UserManager()
: base ( new UserStore< applicationuser>( new ApplicationDbContext()))
{
}
}
}
命名空间 WingtipToys
{
public static class IdentityHelper
{
// 链接外部登录时用于XSRF
public const string XsrfKey = < span class =code-string> XsrfId;
public static void SignIn(UserManager管理器,ApplicationUser用户, bool isPersistent)
{
IAuthenticationManager authenticationManager = HttpContext.Current.GetOwinContext()。
authenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
var identity = manager.CreateIdentity(user,DefaultAuthenticationTypes.ApplicationCookie);
authenticationManager.SignIn( new AuthenticationProperties(){IsPersistent = isPersistent},identity);
}
public const string ProviderNameKey = providerName;
public static string GetProviderNameFromRequest (HttpRequest请求)
{
return request [ProviderNameKey];
}
public static string GetExternalLoginRedirectUrl( string accountProvider)
{
return / Account / RegisterExternalLogin? + ProviderNameKey + = + accountProvider;
}
private static bool IsLocalUrl( string url)
{
return !string.IsNullOrEmpty(url)&& ((url [ 0 ] == ' /'&&(url.Length == 1 ||(url [ 1 ]! = ' /'&& url [ 1 ]!= ' \\')))||(url.Length < span class =code-keyword>> 1 && url [ 0 ] == ' 〜'&& url [ 1 ] == ' /'));
}
public static void RedirectToReturnUrl( string returnUrl,HttpResponse response)
{
if (!String.IsNullOrEmpty(returnUrl)&& IsLocalUrl(returnUrl))
{
response.Redirect(returnUrl);
}
else
{
response.Redirect( 〜/);
}
}
}
#endregion
}
错误3名称空间'Microsoft'中不存在类型或命名空间名称'Owin'(您是否缺少程序集引用?)C :\ Users \ FAIZA \documents\visual studio 2012 \Projects \ WintipToys \WintipToys \ Model #\\IdentityModels.cs 3 17 WintipToys
错误4类型或命名空间名称'IdentityUser'可以找不到(你错过了使用指令或汇编引用吗?)C:\ Users \ FAIZA \documents\visual studio 2012 \Projects \ WintipToys \ WintipToys \ Model #\\IdentityModels.cs 11 36 WintipToys
错误5找不到类型或命名空间名称'IdentityDbContext'(您是否缺少using指令或程序集引用?)C:\ Users\FAIZA \documents\vis ual studio 2012 \Projects \ WintipToys \WintipToys \Models \IdentityModels.cs 15 41 WintipToys
错误1命名空间Microsoft.AspNet中不存在类型或命名空间名称Identity(是你错过了一个程序集参考?)C:\ Users \ FAIZA \documents\visual studio 2012 \Projects \ WintipToys \ WintipToys \ Model =\\IdentityModels.cs 1 24 WintipToys
错误2类型或命名空间名称Identity在命名空间Microsoft.AspNet中不存在(您是否缺少程序集引用?)C:\ Users \ FAIZA \documents\visual studio 2012 \Projects \ WintipToys \\ \\ WintipToys \Models \IdentityModels.cs 2 24 WintipToys
错误6非泛型类型'WingtipToys.Models.UserManager'不能与类型参数C:\ Users\FAIZA \ documentl用于visual studio 2012 \Projects \ WintipToys \ WintipToys \\ Model.\\IdentityModels.cs 24 32 WintipToys
请帮助我解决这些错误并告诉我vs 2012对本教程有效或者不是。
其次是 ProductContext.cs
使用 System.Data.Entity;
命名空间 WingtipToys.Models
{
public class ProductContext:DbContext
{
public ProductContext()
: base ( WingtipToys)
{
}
public DbSet< category>类别{获取; set ; }
public DbSet< product>产品{获取; set ; }
}
}
也出现以下错误:
错误1类型'System.Data.Objects.ObjectContext'在未引用的程序集中定义。您必须添加对程序集'System.Data.Entity,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'的引用。 C:\ Users\FAIZA \documents\visual studio 2012 \Projects \ WintipToys \WintipToys \Models \ ProductContext.cs 7 16 WintipToys
解决方案
右键单击解决方案资源管理器中的引用并添加该引用..
这样做的问题是什么。 ?
am beginner in ASP.net, just started wintip toy tutorial. I am using Microsoft Visual Studio 2012 for Web. But this tutorial required VS 2013. So kindly guide me
1. VS 2012 for web is valid for this tutorail
2. As i am using VS 2012, so it is not creating Models Folder by default.
3. and there is no Default class IndentityModels.cs in. i am making that class manually but it is giving many errors. i.e
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.Owin.Security;
using System.Web;
using System;
using WingtipToys.Models;
namespace WingtipToys.Models
{
// You can add User data for the user by adding more properties to your User class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
public class ApplicationUser : IdentityUser
{
}
public class ApplicationDbContext : IdentityDbContext<applicationuser>
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}
}
#region Helpers
public class UserManager : UserManager<applicationuser>
{
public UserManager()
: base(new UserStore<applicationuser>(new ApplicationDbContext()))
{
}
}
}
namespace WingtipToys
{
public static class IdentityHelper
{
// Used for XSRF when linking external logins
public const string XsrfKey = "XsrfId";
public static void SignIn(UserManager manager, ApplicationUser user, bool isPersistent)
{
IAuthenticationManager authenticationManager = HttpContext.Current.GetOwinContext().Authentication;
authenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
var identity = manager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);
authenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity);
}
public const string ProviderNameKey = "providerName";
public static string GetProviderNameFromRequest(HttpRequest request)
{
return request[ProviderNameKey];
}
public static string GetExternalLoginRedirectUrl(string accountProvider)
{
return "/Account/RegisterExternalLogin?" + ProviderNameKey + "=" + accountProvider;
}
private static bool IsLocalUrl(string url)
{
return !string.IsNullOrEmpty(url) && ((url[0] == '/' && (url.Length == 1 || (url[1] != '/' && url[1] != '\\'))) || (url.Length > 1 && url[0] == '~' && url[1] == '/'));
}
public static void RedirectToReturnUrl(string returnUrl, HttpResponse response)
{
if (!String.IsNullOrEmpty(returnUrl) && IsLocalUrl(returnUrl))
{
response.Redirect(returnUrl);
}
else
{
response.Redirect("~/");
}
}
}
#endregion
}
Error 3 The type or namespace name 'Owin' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) C:\Users\FAIZA\documents\visual studio 2012\Projects\WintipToys\WintipToys\Models\IdentityModels.cs 3 17 WintipToys
Error 4 The type or namespace name 'IdentityUser' could not be found (are you missing a using directive or an assembly reference?) C:\Users\FAIZA\documents\visual studio 2012\Projects\WintipToys\WintipToys\Models\IdentityModels.cs 11 36 WintipToys
Error 5 The type or namespace name 'IdentityDbContext' could not be found (are you missing a using directive or an assembly reference?) C:\Users\FAIZA\documents\visual studio 2012\Projects\WintipToys\WintipToys\Models\IdentityModels.cs 15 41 WintipToys
Error 1 The type or namespace name 'Identity' does not exist in the namespace 'Microsoft.AspNet' (are you missing an assembly reference?) C:\Users\FAIZA\documents\visual studio 2012\Projects\WintipToys\WintipToys\Models\IdentityModels.cs 1 24 WintipToys
Error 2 The type or namespace name 'Identity' does not exist in the namespace 'Microsoft.AspNet' (are you missing an assembly reference?) C:\Users\FAIZA\documents\visual studio 2012\Projects\WintipToys\WintipToys\Models\IdentityModels.cs 2 24 WintipToys
Error 6 The non-generic type 'WingtipToys.Models.UserManager' cannot be used with type arguments C:\Users\FAIZA\documents\visual studio 2012\Projects\WintipToys\WintipToys\Models\IdentityModels.cs 24 32 WintipToys
kindly help me in these errors and also tell me vs 2012 is valid for this tutorial or not.
secondly the class ProductContext.cs
using System.Data.Entity;
namespace WingtipToys.Models
{
public class ProductContext : DbContext
{
public ProductContext()
: base("WingtipToys")
{
}
public DbSet<category> Categories { get; set; }
public DbSet<product> Products { get; set; }
}
}
is also giving the following error:
Error 1 The type 'System.Data.Objects.ObjectContext' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. C:\Users\FAIZA\documents\visual studio 2012\Projects\WintipToys\WintipToys\Models\ProductContext.cs 7 16 WintipToys
解决方案
Right click on the reference in solution explorer and add that reference ..
Whats the problem in doing so . ?
这篇关于如何处理这些错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文