我正在尝试从供应商发布一个网站项目,该供应商的某些文件路径非常漫长.发布时,错误是:
The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.
Run Code Online (Sandbox Code Playgroud)
当我发布时,Visual Studio 2012 Update 3正在尝试写入临时目录,并且前缀很长:
C:\Users\cuser\AppData\Local\Temp\WebSitePublish\MidasCMS400v9-1580334405\obj\Debug\Package\PackageTmp\
Run Code Online (Sandbox Code Playgroud)
我想我可以c:\tem通过遵循这个SO答案将VS重定向到另一个临时目录:发布网站项目时临时路径太长
我创建了我的发布配置文件,一旦打开它,就会出现一个错误,表明它WebPublishMethod不是一个元素PropertyGroup.无论如何,我更新了文件,看起来像这样:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<ExcludeApp_Data>False</ExcludeApp_Data>
<publishUrl>C:\Sites\MidasPublish</publishUrl>
<DeleteExistingFiles>False</DeleteExistingFiles>
<AspnetCompileMergeIntermediateOutputPath>c:\tem\</AspnetCompileMergeIntermediateOutputPath>
</PropertyGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
当我尝试发布时,我得到一个名为"检测到文件修改"的模式框弹出窗口,其中显示消息"项目YourWebsite已在环境外修改",并询问我是否要重新加载.在我的错误列表中,我继续得到关于路径太长的错误,因为它没有尝试使用c:\tem我识别的目录.
我需要将这个血腥的东西放到服务器上,我可以使用任何允许我发布血腥内容的解决方案.我对网站项目模板了解不多,所以如果有更好的方法,请告诉我.
我有以下类和接口:
public interface IThing
{
string Name { get; }
}
public class Thing : IThing
{
public string Name { get; set; }
}
public abstract class ThingConsumer<T> where T : IThing
{
public string Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
现在,我有一个工厂将返回从ThingConsumer派生的对象,如:
public class MyThingConsumer : ThingConsumer<Thing>
{
}
Run Code Online (Sandbox Code Playgroud)
我的工厂目前看起来像这样:
public static class ThingConsumerFactory<T> where T : IThing
{
public static ThingConsumer<T> GetThingConsumer(){
if (typeof(T) == typeof(Thing))
{
return new MyThingConsumer();
}
else
{
return null;
}
}
} …Run Code Online (Sandbox Code Playgroud) 我目前已经搭建了一个视图,其中我的模型的布尔属性被传递给Html.EditorFor帮助器:
@Html.EditorFor(model => model.EndCurrentDeal)
Run Code Online (Sandbox Code Playgroud)
一切都很好,但我真正想要做的就是按下这样的下拉菜单:
<select>
<option value="true" selected="selected">Yes</option>
<option value="false">No</option>
</select>
Run Code Online (Sandbox Code Playgroud)
实现这一目标的最简单方法是什么?
谢谢,
克里斯
是否有理由FindAsync()从IDbSet<T>界面中省略该方法?Find是界面的一部分,异步版本不可用似乎很奇怪.我需要转换DbSet<T>才能访问它,这有点麻烦:
User user = await ((DbSet<User>)db.Users)
.FindAsync("de7d5d4a-9d0f-48ff-9478-d240cd5eb035");
Run Code Online (Sandbox Code Playgroud) 我一直在为我的MVC操作使用压缩过滤器,详见此处:
http://msdn.microsoft.com/en-us/magazine/gg232768.aspx
我试图重新编写代码来为Web API做类似的事情,但我遇到了障碍:
public class CompressAPIAttribute : System.Web.Http.Filters.ActionFilterAttribute
{
public override void OnActionExecuting(System.Web.Http.Controllers.HttpActionContext filterContext)
{
var preferredEncoding = GetPreferredEncoding(filterContext.Request);
Stream compressedStream = null;
// Compress the response accordingly
var response = filterContext.Response;
response.Headers.Add("Content-encoding", preferredEncoding.ToString());
if (preferredEncoding == CompressionScheme.Gzip)
{
response.Content = new GZipStream(compressedStream, CompressionMode.Compress); //THIS WON'T WORK
}
if (preferredEncoding == CompressionScheme.Deflate)
{
response.Content = new DeflateStream(compressedStream, CompressionMode.Compress); //THIS WON'T WORK
}
return;
}
enum CompressionScheme
{
Gzip = 0,
Deflate = 1,
Identity = 2
}
private CompressionScheme …Run Code Online (Sandbox Code Playgroud) 我有一个需要在调整浏览器窗口大小时调整大小的画布,所以我有以下内容:
var resizeCanvas = function () {
var ratio = Math.max(window.devicePixelRatio || 1, 1);
canvas.width = (canvas.offsetWidth || canvas.width) * ratio;
canvas.height = (canvas.offsetHeight || canvas.height) * ratio;
canvas.getContext('2d').scale(ratio, ratio);
}
window.addEventListener('resize', resizeCanvas);
Run Code Online (Sandbox Code Playgroud)
这很有效,除了在移动设备上滚动触发resize事件.
这是不希望的,因为调整画布大小会清除其内容,这意味着当移动用户滚动时,画布总是被擦除.
由于这个答案,我提出了一个基于缓存宽度和双重检查的解决方案,但根据我的设计,我真的只需要解决受我的视口metatag影响的设备的问题:
<meta name="viewport" content="width=device-width, initial-scale=1">
Run Code Online (Sandbox Code Playgroud)
有没有我可以检查浏览器是否正在使用该元标记?我正在寻找类似的东西:
if(viewportMetaTagIsUsed){
//For mobile browsers
window.addEventListener("orientationchange", resizeCanvas);
} else {
//For desktop browsers
window.addEventListener('resize', resizeCanvas);
}
Run Code Online (Sandbox Code Playgroud) 我有一个简单的更新功能:
public void Update(Users user)
{
tblUserData userData = _context.tblUserDatas.Where(u => u.IDUSER == user.IDUSER).FirstOrDefault();
if (userData != null)
{
Mapper.CreateMap<Users, tblUserData>();
userData = Mapper.Map<Users, tblUserData>(user);
_context.SaveChanges()
}
}
Run Code Online (Sandbox Code Playgroud)
userData是一个EF实体,它的Entity Key属性被删除了,因为我相信它存在于目标对象中,但不存在于源对象中,因此它将使用其默认值进行映射(对于Entity Key,它是null )
所以,我的问题是,Automapper是否可以配置为仅尝试映射源对象和目标对象中存在的属性?我想要跳过实体键和导航属性之类的东西.
有点神秘.我有一个带有Year属性的viewmodel:
public class TradeSpendingSalesViewModel
{
public string ProductCode { get; set; }
public IEnumerable<SelectListItem> AllowTypeSelect { get; set; }
public string AllowType { get; set; }
public IEnumerable<SelectListItem> YearsSelect { get; set; }
public int Year { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
如果我将一个空的viewmodel发布到我的控制器:
[HttpPost]
public ActionResult Index(TradeSpendingSalesViewModel vm)
{
var allErrors = ModelState.Values.SelectMany(v => v.Errors);
foreach (var e in allErrors)
{
Response.Write(e.ErrorMessage);
}
}
Run Code Online (Sandbox Code Playgroud)
然后我收到一个错误消息:"年份字段是必需的."
由于我没有使用Required属性注释viewmodel Year字段,因此我不清楚为什么会生成此错误.
有任何想法吗?
我正在构建一个自定义Power BI可视化,因此我可以访问平台使用的javascript文件.我无权访问任何标记,只有一个元素被注入到我可以挂载可视化的位置.
我正在尝试安装Bing Map,文档看起来像这样:
<div id='myMap' style='width: 100vw; height: 100vh;'></div>
<script type='text/javascript'>
var map;
function loadMapScenario() {
map = new Microsoft.Maps.Map(document.getElementById('myMap'), {});
}
</script>
<script type='text/javascript' src='https://www.bing.com/api/maps/mapcontrol?key=YourBingMapsKey&callback=loadMapScenario' async defer></script>
Run Code Online (Sandbox Code Playgroud)
脚本的URL有一个callback查询字符串参数,其中包含要调用的函数的名称.
鉴于我无法访问标记,我正在尝试在可视化构造函数中动态执行所有操作.我创建一个函数,将其移动到全局范围,然后我添加querystring var来引用它,但它永远不会被调用.你能看到我可能遗失的任何东西吗?
constructor(options: VisualConstructorOptions) {
this.host = options.host;
this.elem = options.element;
const self = this;
function moveMethodsIntoGlobalScope(functionName){
var parts = functionName.toString().split('\n');
eval.call(window, parts.splice(1, parts.length - 2).join(''));
}
function methodsToPutInGlobalScope(){
function loadMapScenario(){
console.log("finally called loadMapScenario");
}
}
const script = document.createElement('script');
script.type = 'text/javascript';
script.async = true;
console.log(loadMapScenario === …Run Code Online (Sandbox Code Playgroud) Props我尝试尽可能推断组件的接口而不是导出它们。这不是类和功能组件的问题,但如果我尝试推断Propsa 的接口styled-component,则输入的 propany并不理想。
interface Props {
bgColor: string;
children: React.ReactNode;
}
const Box = styled.div<Props>`
background-color: ${(p) => p.bgColor};
`;
const Button = (props: Props) => (
<button style={{ backgroundColor: props.bgColor }}>{props.children}</button>
);
type ButtonInferredProps = React.ComponentProps<typeof Button>;
type BoxInferredProps = React.ComponentProps<typeof Box>;
const OtherBox = (props: BoxInferredProps) => (
<div style={{ backgroundColor: props.bgColor }}>{props.children}</div>
);
const OtherButton = (props: ButtonInferredProps) => (
<button style={{ backgroundColor: props.bgColor }}>{props.children}</button>
);
export default function App() …Run Code Online (Sandbox Code Playgroud) asp.net-mvc ×3
c# ×3
asp.net ×2
javascript ×2
.net ×1
automapper ×1
generics ×1
html ×1
meta ×1
meta-tags ×1
msbuild ×1
powerbi ×1
reactjs ×1
typescript ×1
viewport ×1